/**
 * webapp的评论
 * 如果已经初始化过，就不在初始化
 */
;
(function($, window, document, undefined) {
    var param, commentMoreUrl, elContentPosterContainer;

    var ContentPoster = function(el, opts) {
        this.el = el;
        this.defaults = {};
        this.options = $.extend({}, this.defaults, opts);
    }


    ContentPoster.prototype = {
        init: function() {
            var me = this,
                el = me.el;

            if (!el.length || el.attr('data-initialized') == 'true') {
                return;
            }

            // me.fetchData();
            me.bindEvents();

            el.attr('data-initialized', 'true');
            return me;
        },
        bindEvents: function() {
            var me = this,
                el = me.el;


        },
        fetchData: function() {
            var me = this,
                el = me.el;

            $.ajax({
                url: '/contents/index.json',
                type: 'GET',
                dataType: 'json',
                data: {},
                success: function(ret) {
                    console.log(ret);

                    me.renderContentPoster(ret);
                },
                error: function(ret) {

                }
            })
        },

        renderContentPoster: function(contents) {
            var me = this,
                el = me.el,
                html = '';

            for (var i = 0; i < contents.length; i++) {
                var contentid = contents[i]._id;
                html += '<tr>' +
                    '<td class="contentid">' + (i + 1) + '</td>' +
                    '<td class="contentname"><a href="#">' + contents[i].contentname + '</a></td>' +
                    '<td class="contentnickname">' + contents[i].nickname + '</td>' +
                    '<td class="contentlist">' + contents[i].list.length + '</td>' +
                    '<td class="contentopp">' +
                    '<a title="' + contents[i].contentname + '" class="button minbutton greenbutton traversebutton">遍历</a>' +
                    '<a data-id="' + contents[i]._id + '" title="' + contents[i].contentname + '" class="button minbutton redbutton deletecontent">删除</a>' +
                    '</td>' + '</tr>';
            }

            $('.content-tbody').html(html);
        }
    }

    $.fn.ContentPoster = function(opts) {
        var comments = new ContentPoster(this, opts);

        return comments.init();
    }
})(window.jQuery || window.Zepto, window, document);
